<%@ page import="java.sql.*" %> 
<%@ page import="java.io.*" %> 
<%@ page import="java.util.Date" %> 
<%@ page import="java.text.DateFormat" %> 
<%@ page import="java.text.SimpleDateFormat" %> 

<% 
	try {
		
		String connectionURL = "jdbc:mysql://localhost:3306/unilearn"; 
		
		int result_count = 0;
		Connection connection = null;
		Statement stmt = null;
		ResultSet rs = null;

		Class.forName("com.mysql.jdbc.Driver").newInstance(); 

		connection = DriverManager.getConnection(connectionURL, "root", "");
		stmt = connection.createStatement();
		
		if(!connection.isClosed())
		{
			
			DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd");
			Date _now = new Date();
			
			
			//get session values
			/*String user_id = (String)session.getAttribute("UserID");
			String permission = (String)session.getAttribute("Permission");
			String first_name = (String)session.getAttribute("LastName");
			String last_name = (String)session.getAttribute("FirstName");
			String class_group_id = (String)session.getAttribute("ClassGroupID");*/
			
			String subject_code = request.getParameter("txtSubjectCode");
			String subject_name = request.getParameter("txtSubjectName");
			
			result_count = stmt.executeUpdate("INSERT INTO subject (subject_code, subject_name)" 
							+ "VALUES ('"+subject_code+"', '"+subject_name+"')");
			
			
			if (result_count > 0)
			{
				out.println( "<script>alert('Subject Create Successful'); window.location='adminSubjectCreate.jsp'</script>" );
			}else
			{
				out.println( "<script>alert('Subject Create Fail'); window.location='adminSubjectCreate.jsp'</script>" );
			}
		}
		
	}catch(Exception ex){

			out.println(ex);
	}

%>
